package com.jgc.future;

import java.util.concurrent.*;

/**
 * Created by Administrator on 2022/3/22.
 */
public class CompletableFutureTest2 {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,10,1L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(50), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 1;
        }).thenApply(f->{
           return f + 2;
        });

        CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 1;
        }).thenApply(f->{
            return f + 2;
        }).whenComplete((v,e)->{
           if(e==null){
               System.out.println("----result" + v);
           }
        }).exceptionally(e ->{
            e.printStackTrace();
            return null;
        });
        System.out.println("-----main over----------");
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        threadPoolExecutor.shutdown();


    }
}
